package com.mjx.algorithm.tool;

import java.util.Random;

/**
 * 工具类
 * Created by meijingxiang on 2017/2/3.
 */
public class Tools {
    /**
     * 生成随机数 并指定范围
     * @param n 数组大小
     * @param min 最小值
     * @param max 最大值
     * @return
     */
    public static int[] generaterArray(int n, int min, int max) {
        int[] array = new int[n];
        Random random=new Random();
        for (int i = 0; i < n; i++) {
            array[i] = random.nextInt(max)%(max - min + 1) +min;
        }
        return array;
    }

    public static int[] generaterArray(int n, int max){
        return generaterArray(n,0,max);
    }

    public static int[] generaterArray(int n){
        return generaterArray(n,0,100);
    }

    public static void printIntArray(int []array){
        if (array.length == 0)
            return;
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();
    }
}
